package Algorithm.LICode;

/*
 * @author 枫城
 * @createTime 2022/8/29 20:43
 * @desc 求中位数
 */
public class MedianNum {
    public static void main(String[] args) {
        int[] num1  = new int[]{1,2, 3};
        int[] num2  = new int[]{2};
        System.out.println(findMedianSortedArrays(num1, num2));

    }

    public static double findMedianSortedArrays(int[] nums1, int[] nums2){
        double median = 0;
        int len = nums1.length + nums2.length;
        int left = -1,right = -1;
        for (int i = 0; i < len/2; i++) {
            left = right;
            if (i<nums1.length&&(nums1[i]<nums2[i])){
                right = nums1[i];
            }else {
                right = nums2[i-nums1.length];
            }
        }
        if (len % 2 == 0){
            return (left +right) / 2.0;
        }else
            return right;

    }


}
